package io_nio;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;

/**
 * Created by butterfly on 2018/6/26.
 */
public class FileDemo {

    public static void main(String[] args) throws IOException {
        File file = new File(".");//当前路径创建文件
        System.out.println(file.getName());
        System.out.println(file.getParent());
        System.out.println(file.getAbsoluteFile());
        System.out.println(file.getAbsoluteFile().getParent());
        File aaa = File.createTempFile("aaa", ".txt", file);//创建一个临时文件
        aaa.deleteOnExit();//退出时删除
        String[] list = file.list(new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                //当前文件夹下以java结尾的文件和文件夹被列出
                return name.endsWith(".java") || new File(name).isDirectory();
            }
        });

    }
}
